define(function(require){
	var $ = require("jquery");
	var justep = require("$UI/system/lib/justep");

	var Model = function(){
	    this.pageNo = 1;
	    this.pageSize = 7;
		this.callParent();
		this.currentId = null;
		this.isInSearch = false;//标记是否是搜索状态
	};

    //获取传过来的参数，再刷新列表
	Model.prototype.modelParamsReceive = function(event){
		this.currentId = this.getContext().getRequestParameter("currentId");
		this.comp("infoData").refreshData();
	};

	Model.prototype.infoDataCustomRefresh = function(event){
	    
	    var me = this;
	    //var id = JSON.parse(localStorage.getItem("userInfo")).data[2].id;
	    if(this.currentId){
	    	var url = "http://www.xjzlhy.com:81/ex_community/a/api/community/getClassInfosByCategoryId?callback=?&category.id="+this.currentId;			
			$.getJSON(
					url,
//					{
//						"office.id":id
//					},
					function(data){
					    if(data && data.data){
					    	me.comp("infoData").loadData(data.data);
							me.comp("popOver1").hide();
					    }
					}
			);
	    }	
	};
	
	Model.prototype.createImageUrl = function(path){
	  
		var url = "http://www.xjzlhy.com:81"+path;
		return url;
	};

	


	Model.prototype.li1Click = function(event){
	
		var row = event.bindingContext.$object;
		
		var option = {
		        id:row.val("id"),
//				title:row.val("title"),
//				description:row.val("description"),
//				updateDate:row.val("updateDate"),
//				content:row.val("content"),
//				image:row.val("image")
		};
		
		//justep.Shell.showPage("$UI/communityOto/category/categoryInfo.w",option);
		justep.Shell.showPage("$UI/communityOto/category/categoryInfo.w?id="+row.val("id"));

	};

	


	Model.prototype.infoDataBeforeRefresh = function(event){
		this.comp("popOver1").show();

	};

	


	Model.prototype.scrollView1PullDown = function(event){
	    this.pageNo++;
		this.comp("infoList").refresh();

	};

	


	Model.prototype.scrollView1PullUp = function(event){
	   this.pageNo--;
	   this.comp("infoList").refresh(true);

	};

	
    Model.prototype.showSearchButtonClick = function(event){
	
		$('.search-panel').slideToggle();

	};
		
	Model.prototype.searchButtonClick = function(event){
	   
		var searchUrl = 'http://www.xjzlhy.com:81/ex_community/a/api/community/getClassInfosByCategoryId?callback=?';
		var title = this.comp("searchContent").val();
		var me  = this;
		if(title){
			$.getJSON(searchUrl,{'category.id':this.currentId,'title':title},function(data){
				if(data && data.data){
				    me.isInSearch = true;
					me.comp("infoData").loadData(data.data);		
				}
			});
		}
	};
		
	

	Model.prototype.backBtnClick = function(event){
		if(this.isInSearch){
		    this.isInSearch = false;
			this.comp("infoData").refreshData();
			this.comp("searchContent").val('');
		}else{
			justep.Shell.closePage();	
		}

	};

	Model.prototype.infoDataAfterRefresh = function(event){
		this.comp("popOver1").hide();
	};

	return Model;
});